import Vue from 'vue'
import Router from 'vue-router'

// 初始路由集
const layout = () => import('../components/layout'),
    home = () => import('../page/home'),
    apply = () => import('../page/appointment'),
    applyPremise = () => import('../page/apply-premise'),
    sweepCodeCheck = () => import('../page/sweep-code-check'),
    accompany = () => import('../page/accompany'),
    sweepCodeRegister = () => import('../page/register'),
    code = () => import('../page/health-code'),
    login = () => import('../page/login'),
    scanCheck = () => import('../page/scan-check'),
    punchCard = () => import('../page/punch-card'),
    uploadCardId = () => import('../page/upload-cardid'),
    lookCardId = () => import('../page/look-card-id'),
    appointment = () => import('../page/reg-appointment'),
    departmentList = () => import('../page/registered-details'),
    appointmentInfo = () => import('../page/appointment-info'),
    personalInfo = () => import('../page/personal-info'),
    personalInfoReplace = () => import('../page/personal-info-replace'),
    appointmentSuccess = () => import('../page/appointment-success'),
    cockpit = () => import('../page/cockpit'),
    cockpitRegCancel = () => import('../page/cockpit-reg-cancel'),
    patient = () => import('../page/patient-list'),
    patientDetail = () => import('../page/patient-detail'),
    constantRouterMap = [
        {
            path: '/',
            name: 'index',
            redirect: '/home',
            component: layout,
            children: [
                {
                    path: '/home',
                    name: 'home',
                    component: home,
                    meta: {
                        title: '首页',
                        keepAlive: false
                    }
                },
                {
                    path: '/appointment-success',
                    name: 'appointmentSuccess',
                    component: appointmentSuccess,
                    meta: {
                        title: '预约挂号成功',
                        keepAlive: false
                    }
                },
                {
                    path: '/login',
                    name: 'login',
                    component: login,
                    meta: {
                        title: '登录页',
                        keepAlive: false
                    }
                },
                {
                    path: '/apply-premise',
                    name: 'applyPremise',
                    component: applyPremise,
                    meta: {
                        title: '防控须知',
                        keepAlive: false
                    }
                },
                {
                    path: '/apply',
                    name: 'apply',
                    component: apply,
                    meta: {
                        title: '预约申请',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'uploadCardId',
                            name: 'uploadCardId',
                            component: uploadCardId,
                            meta: {
                                title: '上传身份证照片',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: '/appointment',
                    name: 'appointment',
                    component: appointment,
                    meta: {
                        title: '预约挂号历史',
                        keepAlive: false
                    }
                },
                {
                    path: '/department-list',
                    name: 'departmentList',
                    component: departmentList,
                    meta: {
                        title: '预约挂号',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'appointmentInfo',
                            name: 'appointmentInfo',
                            component: appointmentInfo,
                            meta: {
                                title: '预约信息',
                                keepAlive: false
                            },
                            children: [
                                {
                                    path: 'personalInfo',
                                    name: 'personalInfo',
                                    component: personalInfo,
                                    meta: {
                                        title: '医生信息',
                                        keepAlive: false
                                    }
                                }
                            ]
                        },
                        {
                            path: 'patient-detail',
                            name: 'departmentPatientDetail',
                            component: patientDetail,
                            meta: {
                                title: '就诊人信息',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: 'replace-doctor',
                    name: 'personalInfoReplace',
                    component: personalInfoReplace,
                    meta: {
                        title: '替诊医生信息',
                        keepAlive: false,
                        transition: true
                    }
                },
                {
                    path: '/sweepCodeCheck',
                    name: 'sweepCodeCheck',
                    component: sweepCodeCheck,
                    meta: {
                        title: '扫码检查',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'accompany',
                            name: 'accompany',
                            component: accompany,
                            meta: {
                                title: '陪同',
                                keepAlive: false
                            }
                        },
                        {
                            path: 'register',
                            name: 'sweepCodeRegister',
                            component: sweepCodeRegister,
                            meta: {
                                title: '预约记录',
                                keepAlive: false
                            }
                        },
                        {
                            path: 'lookCardId',
                            name: 'lookCardId',
                            component: lookCardId,
                            meta: {
                                title: '查看身份证照片',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: '/code',
                    name: 'code',
                    component: code,
                    meta: {
                        title: '查看健康码',
                        keepAlive: false
                    }
                },
                {
                    path: '/scanCheck',
                    name: 'scanCheck',
                    component: scanCheck,
                    meta: {
                        title: '扫码登记',
                        keepAlive: false
                    }
                },
                {
                    path: '/punchCard',
                    name: 'punchCard',
                    component: punchCard,
                    meta: {
                        title: '健康打卡',
                        keepAlive: false
                    }
                },
                {
                    path: '/cockpit',
                    name: 'cockpit',
                    component: cockpit,
                    meta: {
                        title: '驾驶舱',
                        keepAlive: false
                    }
                },
                {
                    path: '/cockpitRegCancel',
                    name: 'cockpitRegCancel',
                    component: cockpitRegCancel,
                    meta: {
                        title: '今日取消预约记录',
                        keepAlive: false
                    }
                },
                {
                    path: '/patient',
                    name: 'patient',
                    component: patient,
                    meta: {
                        title: '就诊人列表',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'patientDetail',
                            component: patientDetail,
                            meta: {
                                title: '就诊人信息',
                                keepAlive: false
                            }
                        }
                    ]
                }
            ]
        }
    ]

let router = new Router({
    mode: 'history',
    routes: constantRouterMap
})

// 路由跳转前更改网页标题
router.beforeEach((to, from, next) => {
    // if (to.meta && to.meta.title) {
    //     document.title = to.meta.title
    // }
    next()
})

Vue.use(Router)

export default router
